﻿// -------------------------------------------------------------------------
//    @FileName         :    NFActivityModule.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-09
//    @Email			:    445267987@qq.com
//    @Module           :    NFActivityModule
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFActivityModule.h"
#include "NFActivityEightPart.h"
#include "NFActivityEightService.h"
#include "NFPacketSendUtil.h"
#include "NFPlayer.h"
#include "NFSession.h"
#include "proto_cs_cmd.nanopb.h"
#include "proto_cs_activity.nanopb.h"

NFActivityModule::NFActivityModule(NFIPluginManager* p):NFLogicDynamicModule(p)
{
}

NFActivityModule::~NFActivityModule()
{
}

int NFActivityModule::Awake()
{
    RegisterClientMessage(NF_ST_LOGIC_SERVER, E_CS_ACTIVITY_DEGREE_GET_ALL_REQ);
    return 0;
}

int NFActivityModule::OnHandleClientMessage(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);
    if (!m_pObjPluginManager->IsInited(NF_ST_LOGIC_SERVER))
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server not inited, drop client msg:{}", packet.ToString());
        return -1;
    }

    if (m_pObjPluginManager->IsServerStopping())
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server is Stopping, drop client msg:{}", packet.ToString());
        return ERR_CODE_SERVER_IS_STOPPING;
    }

    int iRetCode = 0;
    switch (packet.nMsgId)
    {
        case E_CS_ACTIVITY_DEGREE_GET_ALL_REQ:
        {
            iRetCode = OnHandleActivityDegreeGetAllReq(packet, pSession, req);
            break;
        }
        default: NFLogError(NF_LOG_DEFAULT, 0, "not handle msg:{}", packet.nMsgId);
    }

    return iRetCode;
}

int NFActivityModule::OnHandleActivityDegreeGetAllReq(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);

    NFPlayer* pPlayer = pSession->GetPlayer();
    CHECK_NULL(0, pPlayer);

    proto_ff::Proto_CSRsp resp;
    proto_ff::Proto_GCActivityDegreeGetAllRsp* rsp = resp.mutable_activity_degree_get_all_rsp();

    return NFPacketSendUtil::SendToClient(pPlayer, E_GC_ACTIVITY_DEGREE_GET_ALL_RSP, &resp);
}
